package org.imlinker.list;

import javax.swing.Icon;

import org.imlinker.util.StringUtils;

/**
 * 保存在三个列表中统一的类。共有三个属性 icon,title, name.
 * 
 * icon是元素图标，title是显示在列表栏里的文字，name是这个元素的id。
 */

public class ListItem extends Object {

	public ListItem(final Icon paraIcon, final String paraTitle) {
		this(paraIcon, paraTitle, paraTitle);
	}

	public ListItem(final Icon paraIcon, final String paraTitle,
			final String paraName) {
		this(paraIcon, paraTitle, paraName, "");
	}

	public ListItem(final Icon paraIcon, final String paraTitle,
			final String paraName, final String info) {
		this.icon = paraIcon;
		this.title = paraTitle;
		this.name = paraName;
		this.info = info;

		refreshToolTip();
	}

	public Icon getIcon() {
		return icon;
	}

	public void setIcon(Icon icon) {
		this.icon = icon;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;

		refreshToolTip();
	}

	public String getToolTip() {
		return toolTip;
	}

	public void setToolTip(String toolTip) {
		this.toolTip = toolTip;
	}

	public String getInfo() {
		return info;
	}

	public void setInfo(String newInfo) {
		this.info = newInfo;

		refreshToolTip();
	}

	private void refreshToolTip() {
		if (StringUtils.isNotEmpty(info)) {
			setToolTip(this.title + "(" + this.info + ")");
		} else {
			setToolTip(this.title);
		}
	}

	private String title;

	private String name;

	private Icon icon;

	private String toolTip;

	private String info;

}
